package cn.itcast.order.common;

import lombok.Getter;

import java.util.function.Supplier;

@Getter
public enum OrderState {
    /**
     * 订单状态
     * 0 订单创建 初始状态
     * 1 支付中
     * 2 支付成功
     * 3 支付取消
     */
    PAY_CANCEL(3, "支付取消", null),
    PAY_SUCCESS(2, "支付成功", () -> PAY_CANCEL),
    PAY_ING(1, "支付中", () -> PAY_SUCCESS),
    ORDER_CREATED(0, "订单创建", () -> PAY_ING);


    private final int value;
    private final String description;

    public final Supplier<OrderState> nextState;

    OrderState(int value, String description, Supplier<OrderState> nextState) {
        this.value = value;
        this.description = description;
        this.nextState = nextState;
    }

    public static OrderState getOrderState(int code) {
        switch (code) {
            case 0:
                return ORDER_CREATED;
            case 1:
                return PAY_ING;
            case 2:
                return PAY_SUCCESS;
            case 3:
                return PAY_CANCEL;
            default:
                return null;
        }
    }

}
